<?php
/**
 *
 * 版权所有：恰维网络<qwadmin.qiawei.com>
 * 作    者：寒川<hanchuan@qiawei.com>
 * 日    期：2016-01-24
 * 版    本：1.0.0
 * 功能说明：菜单控制器。
 *
 **/

namespace Qwadmin\Controller;

class RmbController extends ComController
{
    public function add()
    {
    	if (IS_POST) {
    	
    		// exit;

    	  
    		  $dada = M('member')->where(array('uid'=>$_SESSION['uid']))->select();
	        $z_id = M('auth_group_access')->where(array('uid'=>$_SESSION['uid']))->select();
	                
	        $b_id = $z_id[0]['group_id'];
	        $m_list = M('auth_group')->where(array('id'=>$b_id))->select();
	        $slist = M('stock')->where(['id'=>$_POST['id']])->select();
	        $list = $_POST;
	      foreach ($list as $k => $v ){
           foreach ($v as $key => $value){
               if (!$value){
                   unset($list[$k][$key]);
                   continue;
               }
           }
           // if(empty($v)){
           //     unset($list[$k]);
           // }
          }
          $result = array_filter($list);
	        
          $result = array_values($result); 
          // dump($arr);
	        // exit;
          $upload = new \Think\Upload();// 实例化上传类
          $upload->maxSize = 3145728 ;// 设置附件上传大小
          $upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
          $upload->rootPath = './Public/Uploads/'; // 设置附件上传根目录
          $upload->savePath = ''; // 设置附件上传（子）目录
          // 上传文件
          $info = $upload->upload();
          // dump($info);
          // exit;
          foreach ($info as $v) {
            // dump($v);
            $img['img'] =  "/Uploads/".$v['savepath'].$v['savename'];
            $img['iname'] =  $v['savename'];
            
          }
          // if (empty($img)) {
          //     $this->error('请上传凭证!');
          //     exit;
          // }
          foreach ($result as $key => $item) {
            $result[$key]['img'] = $img['img'];
            $result[$key]['iname'] = $img['iname'];
          }
          // dump($result);
          // exit;
          switch ($dada[0]['m_type']) {
                  case '2':  //主管
                        // dump($_POST);
                        // exit;
                        if ($m_list[0]['post'] == '行政中心') {
                            
                                      M()->startTrans();
                                      foreach ($result as $value) {
                                          $value['time'] = date('Y-m-d');  //添加时间
                                          $value['ment'] = $m_list[0]['post']; //部门
                                          // $value['type'] = 2;
                                          $value['uname'] = $dada[0]['user']; //申请人
                                          $value['look'] = 8;  //审批值
                                          if (!M('cost')->add($value)) {
                                              M()->rollback();
                                              return $this->error('添加失败');
                                          }
                                      }
                                      M()->commit();
                                   
                                      $count = count($result);
                                      $llist = M('cost')->where(['uname'=>$dada[0]['user']])->order('id desc')->limit($count)->select();
                                       foreach ($llist as  $v) {
                                          // dump($v);
                                          $date['zname'] = $dada[0]['user'];
                                          $date['ztype'] = $dada[0]['m_type'];
                                          $date['stype'] = 1;
                                          $date['ztime'] = date('Y-m-d');
                                          $date['fid'] = $v['id'];
                                          // $date['wtype'] = '急性物品申购';
                                          // dump($date);
                                          $d[] = $date;
                                        }
                                        
                                        // exit;
                                       if (M('fei')->addALL($d) > 0) {
                                             $this->success('添加成功');
                                        } 

                                   



                        }else{
                            if ($m_list[0]['post'] == '采购中心') {

                                
                                      M()->startTrans();
                                      foreach ($result as $value) {
                                          $value['time'] = date('Y-m-d');  //添加时间
                                          $value['ment'] = $m_list[0]['post']; //部门
                                          // $value['type'] = 2;
                                          $value['uname'] = $dada[0]['user']; //申请人
                                          $value['look'] = 9;  //审批值
                                          if (!M('cost')->add($value)) {
                                              M()->rollback();
                                              return $this->error('添加失败');
                                          }
                                      }
                                      M()->commit();
                                   
                                      $count = count($result);
                                      $llist = M('cost')->where(['uname'=>$dada[0]['user']])->order('id desc')->limit($count)->select();
                                       foreach ($llist as  $v) {
                                          // dump($v);
                                          $date['zname'] = $dada[0]['user'];
                                          $date['ztype'] = $dada[0]['m_type'];
                                          $date['stype'] = 1;
                                          $date['ztime'] = date('Y-m-d');
                                          $date['fid'] = $v['id'];
                                          // $date['wtype'] = '急性物品申购';
                                          // dump($date);
                                          $d[] = $date;
                                        }
                                        
                                        // exit;
                                       if (M('fei')->addALL($d) > 0) {
                                             $this->success('添加成功');
                                        } 


                              
                            }else{
                                if ($m_list[0]['post'] == '财务中心') {
                                    
                                    M()->startTrans();
                                      foreach ($result as $value) {
                                          $value['time'] = date('Y-m-d');  //添加时间
                                          $value['ment'] = $m_list[0]['post']; //部门
                                          // $value['type'] = 2;
                                          $value['uname'] = $dada[0]['user']; //申请人
                                          $value['look'] = 10;  //审批值
                                          if (!M('cost')->add($value)) {
                                              M()->rollback();
                                              return $this->error('添加失败');
                                          }
                                      }
                                      M()->commit();
                                   
                                      $count = count($result);
                                      $llist = M('cost')->where(['uname'=>$dada[0]['user']])->order('id desc')->limit($count)->select();
                                       foreach ($llist as  $v) {
                                          // dump($v);
                                          $date['zname'] = $dada[0]['user'];
                                          $date['ztype'] = $dada[0]['m_type'];
                                          $date['stype'] = 1;
                                          $date['ztime'] = date('Y-m-d');
                                          $date['fid'] = $v['id'];
                                          // $date['wtype'] = '急性物品申购';
                                          // dump($date);
                                          $d[] = $date;
                                        }
                                        
                                        // exit;
                                       if (M('fei')->addALL($d) > 0) {
                                             $this->success('添加成功');
                                        } 

                                }else{
                                  // echo '12';
                                  // exit;
                                    
                                       M()->startTrans();
                                      foreach ($result as $value) {
                                          $value['time'] = date('Y-m-d');  //添加时间
                                          $value['ment'] = $m_list[0]['post']; //部门
                                          // $value['type'] = 2;
                                          $value['uname'] = $dada[0]['user']; //申请人
                                          $value['look'] = 1;  //审批值
                                          if (!M('cost')->add($value)) {
                                              M()->rollback();
                                              return $this->error('添加失败');
                                          }
                                      }
                                      M()->commit();
                                   
                                      $count = count($result);
                                      $llist = M('cost')->where(['uname'=>$dada[0]['user']])->order('id desc')->limit($count)->select();
                                       foreach ($llist as  $v) {
                                          // dump($v);
                                          $date['zname'] = $dada[0]['user'];
                                          $date['ztype'] = $dada[0]['m_type'];
                                          $date['stype'] = 1;
                                          $date['ztime'] = date('Y-m-d');
                                          $date['fid'] = $v['id'];
                                          // $date['wtype'] = '急性物品申购';
                                          // dump($date);
                                          $d[] = $date;
                                        }
                                        
                                        // exit;
                                       if (M('fei')->addALL($d) > 0) {
                                             $this->success('添加成功');
                                        } 
                                }
                            }
                        }
                    break;
                  case '3':  //经理
                      // echo '111';
                      // exit;
                      M()->startTrans();
                                      foreach ($result as $value) {
                                          $value['time'] = date('Y-m-d');  //添加时间
                                          $value['ment'] = $m_list[0]['post']; //部门
                                          // $value['type'] = 2;
                                          $value['uname'] = $dada[0]['user']; //申请人
                                          $value['look'] = 2;  //审批值
                                          if (!M('cost')->add($value)) {
                                              M()->rollback();
                                              return $this->error('添加失败');
                                          }
                                      }
                                      M()->commit();
                                   
                                      $count = count($result);
                                      $llist = M('cost')->where(['uname'=>$dada[0]['user']])->order('id desc')->limit($count)->select();
                                       foreach ($llist as  $v) {
                                          // dump($v);
                                          $date['jname'] = $dada[0]['user'];
                                          $date['jtype'] = $dada[0]['m_type'];
                                          $date['stype'] = 1;
                                          $date['jtime'] = date('Y-m-d');
                                          $date['fid'] = $v['id'];
                                          // $date['wtype'] = '急性物品申购';
                                          // dump($date);
                                          $d[] = $date;
                                        }
                                        
                                        // exit;
                                       if (M('fei')->addALL($d) > 0) {
                                             $this->success('添加成功');
                                        } 

                     
                    break;
                  case '4':  //行政
                      
                      M()->startTrans();
                                      foreach ($result as $value) {
                                          $value['time'] = date('Y-m-d');  //添加时间
                                          $value['ment'] = $m_list[0]['post']; //部门
                                          // $value['type'] = 2;
                                          $value['uname'] = $dada[0]['user']; //申请人
                                          $value['look'] = 8;  //审批值
                                          if (!M('cost')->add($value)) {
                                              M()->rollback();
                                              return $this->error('添加失败');
                                          }
                                      }
                                      M()->commit();
                                   
                                      $count = count($result);
                                      $llist = M('cost')->where(['uname'=>$dada[0]['user']])->order('id desc')->limit($count)->select();
                                       foreach ($llist as  $v) {
                                          // dump($v);
                                          $date['zname'] = $dada[0]['user'];
                                          $date['ztype'] = $dada[0]['m_type'];
                                          $date['stype'] = 1;
                                          $date['ztime'] = date('Y-m-d');
                                          $date['fid'] = $v['id'];
                                          // $date['wtype'] = '急性物品申购';
                                          // dump($date);
                                          $d[] = $date;
                                        }
                                        
                                        // exit;
                                       if (M('fei')->addALL($d) > 0) {
                                             $this->success('添加成功');
                                        } 

                    break;
                  case '5':   //财务
                       
                        M()->startTrans();
                                      foreach ($result as $value) {
                                          $value['time'] = date('Y-m-d');  //添加时间
                                          $value['ment'] = $m_list[0]['post']; //部门
                                          // $value['type'] = 2;
                                          $value['uname'] = $dada[0]['user']; //申请人
                                          $value['look'] = 10;  //审批值
                                          if (!M('cost')->add($value)) {
                                              M()->rollback();
                                              return $this->error('添加失败');
                                          }
                                      }
                                      M()->commit();
                                   
                                      $count = count($result);
                                      $llist = M('cost')->where(['uname'=>$dada[0]['user']])->order('id desc')->limit($count)->select();
                                       foreach ($llist as  $v) {
                                          // dump($v);
                                          $date['zname'] = $dada[0]['user'];
                                          $date['ztype'] = $dada[0]['m_type'];
                                          $date['stype'] = 1;
                                          $date['ztime'] = date('Y-m-d');
                                          $date['fid'] = $v['id'];
                                          // $date['wtype'] = '急性物品申购';
                                          // dump($date);
                                          $d[] = $date;
                                        }
                                        
                                        // exit;
                                       if (M('fei')->addALL($d) > 0) {
                                             $this->success('添加成功');
                                        } 

                    break;

                  case '10':   //财务
                       
                        M()->startTrans();
                                      foreach ($result as $value) {
                                          $value['time'] = date('Y-m-d');  //添加时间
                                          $value['ment'] = $m_list[0]['post']; //部门
                                          // $value['type'] = 2;
                                          $value['uname'] = $dada[0]['user']; //申请人
                                          $value['look'] = 10;  //审批值
                                          if (!M('cost')->add($value)) {
                                              M()->rollback();
                                              return $this->error('添加失败');
                                          }
                                      }
                                      M()->commit();
                                   
                                      $count = count($result);
                                      $llist = M('cost')->where(['uname'=>$dada[0]['user']])->order('id desc')->limit($count)->select();
                                       foreach ($llist as  $v) {
                                          // dump($v);
                                          $date['zname'] = $dada[0]['user'];
                                          $date['ztype'] = $dada[0]['m_type'];
                                          $date['stype'] = 1;
                                          $date['ztime'] = date('Y-m-d');
                                          $date['fid'] = $v['id'];
                                          // $date['wtype'] = '急性物品申购';
                                          // dump($date);
                                          $d[] = $date;
                                        }
                                        
                                        // exit;
                                       if (M('fei')->addALL($d) > 0) {
                                             $this->success('添加成功');
                                        } 

                    break;


                  case '8':   //职能总
                      
                      M()->startTrans();
                                      foreach ($result as $value) {
                                          $value['time'] = date('Y-m-d');  //添加时间
                                          $value['ment'] = $m_list[0]['post']; //部门
                                          // $value['type'] = 2;
                                          $value['uname'] = $dada[0]['user']; //申请人
                                          $value['look'] = 2;  //审批值
                                          if (!M('cost')->add($value)) {
                                              M()->rollback();
                                              return $this->error('添加失败');
                                          }
                                      }
                                      M()->commit();
                                   
                                      $count = count($result);
                                      $llist = M('cost')->where(['uname'=>$dada[0]['user']])->order('id desc')->limit($count)->select();
                                       foreach ($llist as  $v) {
                                          // dump($v);
                                          $date['jname'] = $dada[0]['user'];
                                          $date['jtype'] = $dada[0]['m_type'];
                                          $date['stype'] = 1;
                                          $date['jtime'] = date('Y-m-d');
                                          $date['fid'] = $v['id'];
                                          // $date['wtype'] = '急性物品申购';
                                          // dump($date);
                                          $d[] = $date;
                                        }
                                        
                                        // exit;
                                       if (M('fei')->addALL($d) > 0) {
                                             $this->success('添加成功');
                                        } 

                    break;
                  case '9':   //网络总
                      
                      M()->startTrans();
                                      foreach ($result as $value) {
                                          $value['time'] = date('Y-m-d');  //添加时间
                                          $value['ment'] = $m_list[0]['post']; //部门
                                          // $value['type'] = 2;
                                          $value['uname'] = $dada[0]['user']; //申请人
                                          $value['look'] = 2;  //审批值
                                          if (!M('cost')->add($value)) {
                                              M()->rollback();
                                              return $this->error('添加失败');
                                          }
                                      }
                                      M()->commit();
                                   
                                      $count = count($result);
                                      $llist = M('cost')->where(['uname'=>$dada[0]['user']])->order('id desc')->limit($count)->select();
                                       foreach ($llist as  $v) {
                                          // dump($v);
                                          $date['jname'] = $dada[0]['user'];
                                          $date['jtype'] = $dada[0]['m_type'];
                                          $date['stype'] = 1;
                                          $date['jtime'] = date('Y-m-d');
                                          $date['fid'] = $v['id'];
                                          // $date['wtype'] = '急性物品申购';
                                          // dump($date);
                                          $d[] = $date;
                                        }
                                        
                                        // exit;
                                       if (M('fei')->addALL($d) > 0) {
                                             $this->success('添加成功');
                                        } 

                    break;
                case '0':
                        M()->startTrans();
                        foreach ($result as $value) {
                            $value['time'] = date('Y-m-d');  //添加时间
                            $value['ment'] = $m_list[0]['post']; //部门
                            // $value['type'] = 2;
                            $value['uname'] = $dada[0]['user']; //申请人
                            $value['look'] = 0;  //审批值
                            if (!M('cost')->add($value)) {
                                M()->rollback();
                                return $this->error('添加失败');
                            }
                        }
                        M()->commit();
                        return $this->success('添加成功');
                     //  foreach ($result as  $value) {
                     //    $value['time'] = date('Y-m-d');
                     //    $value['ment'] = $m_list[0]['post'];
                     //    // $value['type'] = 2;
                     //    $value['uname'] = $dada[0]['user'];
                     //    $value['look'] = 0;
                     //    // $value['ju'] = 0;
                     //    $r[] = $value;                       
                     //  }
                     //  dump($r);
                     //  exit;
                     // if (M('cost')->add($r[0]) > 0) {
                     //      $this->success('添加成功');
                     //  }else{
                     //      $this->error('添加失败');
                     //  }
                    break;
            }
    	}else{
    		$this->display();
    	}
    }






    public function feis()
    {
    	  // dump($_GET);
        // $type = $_GET['type'];
        $gid = M('auth_group_access')->where(['uid'=>$_SESSION['uid']])->select();
        // dump($gid);
        // exit;
        $glist = M('auth_group')->where(['id'=>$gid[0]['group_id']])->select();
        // dump($glist);
        // exit;
        $ulist = M('member')->where(['uid'=>$_SESSION['uid']])->select();
        $apost = $glist[0]['post'];
         
      // if ($glist[0]['title'] == '超级管理员') {
      //         $db = M("look");
      //             // $where = "a_id=".$uid;
      //             $count = $db->where(['type'=>3])->count();
      //             $pagecount = 10;
      //             $page = new \Think\Page($count , $pagecount);
      //             // $row[] = '';
      //             $page->parameter = $row; //此处的row是数组，为了传递查询条件
      //             $page->setConfig('first','第一页');
      //             $page->setConfig('prev','上一页');
      //             $page->setConfig('next','下一页');
      //             $page->setConfig('last','尾页');
      //             $page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% 第 '.I('p',1).' 页/共 %TOTAL_PAGE% 页 ( '.$pagecount.' 条/页 共 %TOTAL_ROW% 条)');
      //             $show = $page->show();
      //             $list = $db->where(['type'=>3])->order('id desc')->limit($page->firstRow.','.$page->listRows)->select();
      //             $title = '部门月度申请审批';
      //             $this->assign('list',$list);
      //             $this->assign('page',$show);
      //             $this->assign('title',$title);
      //         $this->display();
      //   exit;
      // }

        switch ($ulist[0]['m_type']) {
          case '2':   //主管
              $db = M("cost");
              // echo '111';
              // exit;
                  // $where = "a_id=".$uid;
                  $count = $db->where(['look'=>0,'ment'=>$apost,'ju'=>0])->count();
                  // dump($apost);
                  // exit;
                  $pagecount = 10;
                  $page = new \Think\Page($count , $pagecount);
                  // $row[] = '';
                  $page->parameter = $row; //此处的row是数组，为了传递查询条件
                  $page->setConfig('first','第一页');
                  $page->setConfig('prev','上一页');
                  $page->setConfig('next','下一页');
                  $page->setConfig('last','尾页');
                  $page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% 第 '.I('p',1).' 页/共 %TOTAL_PAGE% 页 ( '.$pagecount.' 条/页 共 %TOTAL_ROW% 条)');
                  $show = $page->show();
                  $list = $db->where(['look'=>0,'ment'=>$apost,'ju'=>0])->order('id desc')->limit($page->firstRow.','.$page->listRows)->select();
                  $title = '部门费用报销审批';
                  $this->assign('list',$list);
                  $this->assign('page',$show);
                  $this->assign('title',$title);
              $this->display();
            break;



          case '3':   //经理


              switch ($apost) {
                case '行政中心':
                    $db = M("cost");
                    // echo '111';
                    // exit;
                        // $where = "a_id=".$uid;
                        $count = $db->where(['look'=>8,'ment'=>$apost,'ju'=>0])->count();
                        // dump($count);
                        // exit;
                        $pagecount = 9;
                        $page = new \Think\Page($count , $pagecount);
                        // $row[] = '';
                        $page->parameter = $row; //此处的row是数组，为了传递查询条件
                        $page->setConfig('first','第一页');
                        $page->setConfig('prev','上一页');
                        $page->setConfig('next','下一页');
                        $page->setConfig('last','尾页');
                        $page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% 第 '.I('p',1).' 页/共 %TOTAL_PAGE% 页 ( '.$pagecount.' 条/页 共 %TOTAL_ROW% 条)');
                        $show = $page->show();
                        $list = $db->where(['look'=>8,'ment'=>$apost,'ju'=>0])->order('id desc')->limit($page->firstRow.','.$page->listRows)->select();
                        $title = '部门费用报销审批';


                        //---------------------------------------
                       
                        $lei = '行政';
                        $cao = 1;//行政操作分类
                        $this->assign('list',$list);
                        $this->assign('lei',$lei);
                        $this->assign('cao',$cao);
                       
                        $this->assign('page',$show);
                        
                        $this->assign('title',$title);
                    $this->display();
                  break;

                case '采购中心':
                    $db = M("cost");
                    // echo '111';
                    // exit;
                        // $where = "a_id=".$uid;
                        $count = $db->where(['look'=>9,'ment'=>$apost,'ju'=>0])->count();
                        // dump($count);
                        // exit;
                        $pagecount = 9;
                        $page = new \Think\Page($count , $pagecount);
                        // $row[] = '';
                        $page->parameter = $row; //此处的row是数组，为了传递查询条件
                        $page->setConfig('first','第一页');
                        $page->setConfig('prev','上一页');
                        $page->setConfig('next','下一页');
                        $page->setConfig('last','尾页');
                        $page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% 第 '.I('p',1).' 页/共 %TOTAL_PAGE% 页 ( '.$pagecount.' 条/页 共 %TOTAL_ROW% 条)');
                        $show = $page->show();
                        $list = $db->where(['look'=>9,'ment'=>$apost,'ju'=>0])->order('id desc')->limit($page->firstRow.','.$page->listRows)->select();
                        $title = '部门费用报销审批';


                        //---------------------------------------
                       
                    
                        $this->assign('list',$list);
                       
                        $this->assign('page',$show);
                        
                        $this->assign('title',$title);
                        $this->display();
                  break;
                case '财务中心':
                    $db = M("cost");
                    
                        $count = $db->where(['look'=>10,'ment'=>$apost,'ju'=>0])->count();
                        // dump($count);
                        // exit;
                        $pagecount = 9;
                        $page = new \Think\Page($count , $pagecount);
                        $page->parameter = $row; //此处的row是数组，为了传递查询条件
                        $page->setConfig('first','第一页');
                        $page->setConfig('prev','上一页');
                        $page->setConfig('next','下一页');
                        $page->setConfig('last','尾页');
                        $page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% 第 '.I('p',1).' 页/共 %TOTAL_PAGE% 页 ( '.$pagecount.' 条/页 共 %TOTAL_ROW% 条)');
                        $show = $page->show();
                        $list = $db->where(['look'=>10,'ment'=>$apost,'ju'=>0])->order('id desc')->limit($page->firstRow.','.$page->listRows)->select();
                        $title = '部门费用报销审批';


                        //---------------------------------------
                       
                        $lei = '财务';
                        $this->assign('list',$list);
                        $this->assign('lei',$lei);
                       
                        $this->assign('page',$show);
                        
                        $this->assign('title',$title);
                        $this->display();
                  break;
                
                
              }

            break;
          

        

          case '10':  //财务
              $db = M("cost");
                  // $where = "a_id=".$uid;
                  $count = $db->where(array('look'=>2,'ju'=>0))->count();
                  $pagecount = 10;
                  $page = new \Think\Page($count , $pagecount);
                  // $row[] = '';
                  $page->parameter = $row; //此处的row是数组，为了传递查询条件
                  $page->setConfig('first','第一页');
                  $page->setConfig('prev','上一页');
                  $page->setConfig('next','下一页');
                  $page->setConfig('last','尾页');
                  $page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% 第 '.I('p',1).' 页/共 %TOTAL_PAGE% 页 ( '.$pagecount.' 条/页 共 %TOTAL_ROW% 条)');
                  $show = $page->show();
                  $list = $db->where(array('look'=>2,'ju'=>0))->order('ment desc')->limit($page->firstRow.','.$page->listRows)->select();
                  $title = '公司费用报销审批';
                  $lei = 1;
                  $ylist = $db->where(array('look'=>2,'ju'=>0))->select();
                  // foreach ($ylist as  $v) {
                  //   $coun += $v['zong']; 
                  // }
                  // $this->assign('coun',$coun);
                  $zong = 1;
                  $this->assign('zong',$zong);
                  $this->assign('list',$list);
                  $this->assign('lei',$lei);
                  $this->assign('page',$show);
                  $this->assign('title',$title);
              $this->display();
            break;



          case '9':  //职能总经理
              $db = M("cost");
              $mlist = M('auth_group')->where(['mtype'=>2])->select();

              foreach ($mlist as $vn) {
            
                $ments[] =  $vn['title'];
              

              }
               $where = [
                      'ment' => [
                          'in',
                          $ments
                      ],
                      'look' => 1,
                      
                      'ju'   => 0

                  ];

                
                  $count = $db->where($where)->count();
                  
                  $pagecount = 10;
                  $page = new \Think\Page($count , $pagecount);
                  // $row[] = '';
                  $page->parameter = $row; //此处的row是数组，为了传递查询条件
                  $page->setConfig('first','第一页');
                  $page->setConfig('prev','上一页');
                  $page->setConfig('next','下一页');
                  $page->setConfig('last','尾页');
                  $page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% 第 '.I('p',1).' 页/共 %TOTAL_PAGE% 页 ( '.$pagecount.' 条/页 共 %TOTAL_ROW% 条)');
                  $show = $page->show();
                  $list = $db->where($where)->order('ment desc')->limit($page->firstRow.','.$page->listRows)->select();
                  $title = '部门费用报销审批';
                  $lei = '总经理';
                  // $ylist = $db->where(array('type'=>1,'look'=>1,'ju'=>0))->select();
                  // foreach ($ylist as  $v) {
                  //   $coun += $v['zong']; 
                  // }
                  $this->assign('coun',$coun);
                  $this->assign('list',$list);
                  $this->assign('lei',$lei);
                  $this->assign('page',$show);
                  $this->assign('title',$title);
                  $this->display();
            break;




          case '8':  //网络中心总经理
              $db = M("cost");
              $mlist = M('auth_group')->where(['mtype'=>1])->select();

              foreach ($mlist as $vn) {
              // echo $v['n_id'];
              // exit;
              // $ment .= "`ment`="."'".$vn['title']."'"." or ";
              // $ment .= "'".$vn['title']."'"." , ";
                $ments[] =  $vn['title'];
                // 

              }
               $where = [
                      'ment' => [
                          'in',
                          $ments
                      ],
                      'look' => 1,
                     
                      'ju'   => 0

                  ];

                  // dump($where);
                  // exit;
                  // $where = "a_id=".$uid;
                  $count = $db->where($where)->count();
                  // dump($count);
                  // exit;
                  $pagecount = 10;
                  $page = new \Think\Page($count , $pagecount);
                  // $row[] = '';
                  $page->parameter = $row; //此处的row是数组，为了传递查询条件
                  $page->setConfig('first','第一页');
                  $page->setConfig('prev','上一页');
                  $page->setConfig('next','下一页');
                  $page->setConfig('last','尾页');
                  $page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% 第 '.I('p',1).' 页/共 %TOTAL_PAGE% 页 ( '.$pagecount.' 条/页 共 %TOTAL_ROW% 条)');
                  $show = $page->show();
                  $list = $db->where($where)->order('ment desc')->limit($page->firstRow.','.$page->listRows)->select();
                  $title = '部门费用报销审批';
                  // $lei = 1;
                  // $alist = M('look')->order('ment desc')->select();
                  // dump($alist);
                  // exit;
                  // $b = 0;
                  // foreach ($list as  $v) {
                  //  $b += $v['']
                  // }
                  // field()
                  $this->assign('list',$list);
                  // $this->assign('lei',$lei);
                  $this->assign('page',$show);
                  $this->assign('title',$title);
              $this->display();
            break;


          case '6':  //董事办
                  $db = M("cost");
                  // $where = "a_id=".$uid;
                  $count = $db->where(['look'=>5,'ju'=>0])->count();
                  $pagecount = 10;
                 
                  $page = new \Think\Page($count , $pagecount);
                  // $row[] = '';
                  $page->parameter = $row; //此处的row是数组，为了传递查询条件
                  $page->setConfig('first','第一页');
                  $page->setConfig('prev','上一页');
                  $page->setConfig('next','下一页');
                  $page->setConfig('last','尾页');
                  $page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% 第 '.I('p',1).' 页/共 %TOTAL_PAGE% 页 ( '.$pagecount.' 条/页 共 %TOTAL_ROW% 条)');
                  $show = $page->show();
                  $list = $db->where(['look'=>5,'ju'=>0])->order('ment desc')->limit($page->firstRow.','.$page->listRows)->select();
                  $title = '公司费用报销审批';
                  $lei = 1;
                  // $alist = M('look')->order('ment desc')->select();
                  // dump($list);
                  // exit;
                  // $b = 0;
                  // foreach ($list as  $v) {
                  //  $b += $v['']
                  // }
                  // field()
                 
                  // $this->assign('coun',$coun);
                  $zong = 1;
                  $this->assign('zong',$zong);
                  $this->assign('list',$list);
                  $this->assign('lei',$lei);
                  $this->assign('page',$show);
                  $this->assign('title',$title);
              $this->display();
            break;

          }
    }







    //费用报销审核
    public function fsh()
    {


    		$sid = $_POST['id'];
    			
				$slist = M('look')->where(['id'=>$sid])->select();//查询申请物资信息
				$ulist = M('member')->where(['uid'=>$_SESSION['uid']])->select();
				$alist = M('auth_group_access')->where(['uid'=>$_SESSION['uid']])->select();
				$glist = M('auth_group')->where(['id'=>$alist[0]['group_id']])->select();
				$data['fid'] = $sid;
				$data['stype'] = '1';
				// $data['wtype'] = '急性物品申购';
				switch ($ulist[0]['m_type']) {
					case '2': //主管
						
						$data['ztype'] = $ulist[0]['m_type'];
						$data['zname'] = $ulist[0]['user'];
						$data['ztime'] = date('Y-m-d');
						$look['look'] = '1';
						if (M('fei')->add($data) > 0) {
							if (M('cost')->where(['id'=>$sid])->save($look) > 0) {
								echo '1111';
							}
						}
						break;
					case '3': //经理
						switch ($glist[0]['post']) {
							case '行政中心':
								// $ylist = M('sh')->where(['sid'=>$sid])->find();
								
								
									$data['jtype'] = $ulist[0]['m_type'];
									$data['jname'] = $ulist[0]['user'];
									$data['jtime'] = date('Y-m-d');
									$look['look'] = '2';
									if (M('fei')->where(['fid'=>$sid])->save($data) > 0) {
										if (M('cost')->where(['id'=>$sid])->save($look) > 0) {
											echo '1111';
										}
									}
								
								
								break;
							case '采购中心':
								$data['jtype'] = $ulist[0]['m_type'];
								$data['jname'] = $ulist[0]['user'];
								$data['jtime'] = date('Y-m-d');
								$look['look'] = '2';
								if (M('fei')->where(['fid'=>$sid])->save($data) > 0) {
									if (M('cost')->where(['id'=>$sid])->save($look) > 0) {
										echo '1111';
									}
								}
								break;
							case '财务中心':
								$ylist = M('fei')->where(['fid'=>$sid])->find();
								
								if (empty($ylist['jname'])) {
									$data['jtype'] = $ulist[0]['m_type'];
									$data['jname'] = $ulist[0]['user'];
									$data['jtime'] = date('Y-m-d');
									$look['look'] = '2';
									if (M('fei')->where(['fid'=>$sid])->save($data) > 0) {
										if (M('cost')->where(['id'=>$sid])->save($look) > 0) {
											echo '1111';
										}
									}
								}else{
									$data['cjtype'] = $ulist[0]['m_type'];
									$data['cjname'] = $ulist[0]['user'];
									$data['cjtime'] = date('Y-m-d');
									$look['look'] = '4';
									if (M('fei')->where(['fid'=>$sid])->save($data) > 0) {
										if (M('cost')->where(['id'=>$sid])->save($look) > 0) {
											echo '1111';
										}
									}
								}
								break;
							
						}
					
						break;

					

          case '10': //财务(报销)
          // echo'111';
          // exit;
            $data['ctype'] = $ulist[0]['m_type'];
            $data['cname'] = $ulist[0]['user'];
            $data['ctime'] = date('Y-m-d');
            $look['look'] = '4';
            if (M('fei')->where(['fid'=>$sid])->save($data) > 0) {
              if (M('cost')->where(['id'=>$sid])->save($look) > 0) {
                echo '1111';
              }
            }
            break;


					// case '5': //财务
					// // echo'111';
					// // exit;
					// 	$data['cjtype'] = $ulist[0]['m_type'];
					// 	$data['cjname'] = $ulist[0]['user'];
					// 	$data['cjtime'] = date('Y-m-d');
					// 	$look['look'] = '4';
					// 	if (M('fei')->where(['fid'=>$sid])->save($data) > 0) {
					// 		if (M('cost')->where(['id'=>$sid])->save($look) > 0) {
					// 			echo '1111';
					// 		}
					// 	}
					// 	break;

					case '9': //职能总经理
						$shlist = M('fei')->where(['fid'=>$sid])->select();
						// dump($shlist);
						// exit;
						if (empty($shlist[0]['cname'])) {
							$data['jtype'] = $ulist[0]['m_type'];
							$data['jname'] = $ulist[0]['user'];
							$data['jtime'] = date('Y-m-d');
							$look['look'] = '2';
							// dump($data);
							// exit;
							if (M('fei')->where(['fid'=>$sid])->save($data) > 0) {
								if (M('cost')->where(['id'=>$sid])->save($look) > 0) {
									echo '1111';
								}
							}
						}else{
							$data['gtype'] = $ulist[0]['m_type'];
							$data['gname'] = $ulist[0]['user'];
							$data['gtime'] = date('Y-m-d');
							$look['look'] = '5';
							// dump($data);
							// exit;
							if (M('fei')->where(['fid'=>$sid])->save($data) > 0) {
								if (M('cost')->where(['id'=>$sid])->save($look) > 0) {
									echo '1111';
								}
							}
						}
						
						break;
					case '8': //网络总经理
					
						$data['jtype'] = $ulist[0]['m_type'];
						$data['jname'] = $ulist[0]['user'];
						$data['jtime'] = date('Y-m-d');
						$look['look'] = '2';
						// dump($data);
						// exit;
						if (M('fei')->where(['fid'=>$sid])->save($data) > 0) {
							if (M('cost')->where(['id'=>$sid])->save($look) > 0) {
								echo '1111';
							}
						}
						break;

					case '6': //董事办
					
						$data['dtype'] = $ulist[0]['m_type'];
						$data['dname'] = $ulist[0]['user'];
						$data['dtime'] = date('Y-m-d');
						$look['look'] = '6';
						// dump($data);
						// exit;
						if (M('fei')->where(['fid'=>$sid])->save($data) > 0) {
							if (M('cost')->where(['id'=>$sid])->save($look) > 0) {
								echo '1111';
							}
						}
						break;

					
				}
    }







    public function fju()
    {
    	$ulist = M('member')->where(['uid'=>$_SESSION['uid']])->select();
		$alist = M('auth_group_access')->where(['uid'=>$_SESSION['uid']])->select();
		$glist = M('auth_group')->where(['id'=>$alist[0]['group_id']])->select();
		$llist = M('look')->where(['id'=>$_POST['id']])->find();
		$data['stype'] = '2';
		$data['content'] = $_POST['cent'];
		// $type = $_POST['type'];
					switch ($ulist[0]['m_type']) {
							case '2':  //主管
								$data['ztype'] = $ulist[0]['m_type'];
										
								$data['zname'] = $ulist[0]['user'];
								$data['ztime'] = date('Y-m-d');
								$data['fid'] = $_POST['id'];
								// $data['cent'] = $_POST['cent'];
								// $data['stype'] = '2';
								$look['ju'] = '1';
												// dump($data);

								if (M('fei')->add($data) > 0) {
									if (M('cost')->where(['id'=>$_POST['id']])->save($look) > 0) {
										echo '1111';
									}
								}
								break;
							case '3': //经理/总监
										switch ($glist[0]['post']) {
											case '行政中心':
												
												
													$data['jtype'] = $ulist[0]['m_type'];
													$data['jname'] = $ulist[0]['user'];
													$data['jtime'] = date('Y-m-d');
													$look['ju'] = '2';
													if (M('fei')->where(['fid'=>$_POST['id']])->save($data) > 0) {
														if (M('cost')->where(['id'=>$_POST['id']])->save($look) > 0) {
															echo '1111';
														}
													}
												
												
												break;
											case '采购中心':
												$data['jtype'] = $ulist[0]['m_type'];
												$data['jname'] = $ulist[0]['user'];
												$data['jtime'] = date('Y-m-d');
												$look['ju'] = '2';
												if (M('fei')->where(['fid'=>$_POST['id']])->save($data) > 0) {
													if (M('cost')->where(['id'=>$_POST['id']])->save($look) > 0) {
														echo '1111';
													}
												}
												break;
											case '财务中心':
													$ylist = M('fei')->where(['fid'=>$_POST['id']])->find();
													if (empty($ylist['jname'])) {
														$data['jtype'] = $ulist[0]['m_type'];
														$data['jname'] = $ulist[0]['user'];
														$data['jtime'] = date('Y-m-d');
														$look['ju'] = '2';
														if (M('fei')->where(['fid'=>$_POST['id']])->save($data) > 0) {
															if (M('cost')->where(['id'=>$_POST['id']])->save($look) > 0) {
																echo '1111';
															}
														}
													}else{
														$data['cjtype'] = $ulist[0]['m_type'];
														$data['cjname'] = $ulist[0]['user'];
														$data['cjtime'] = date('Y-m-d');
														$look['ju'] = '4';
														if (M('fei')->where(['fid'=>$_POST['id']])->save($data) > 0) {
															if (M('cost')->where(['id'=>$_POST['id']])->save($look) > 0) {
																echo '1111';
															}
														}
													}
													
												
												break;
											
										}

										break;



							case '10':  //财务
								$data['ctype'] = $ulist[0]['m_type'];
										
								$data['cname'] = $ulist[0]['user'];
								$data['ctime'] = date('Y-m-d');
								
								$look['ju'] = '3';
												// dump($data);
												// exit;
								if (M('fei')->where(['fid'=>$_POST['id']])->save($data) > 0) {
									if (M('cost')->where(['id'=>$_POST['id']])->save($look) > 0) {
										echo '1111';
									}
								}
								break;
							case '9':  //职能总经理
								$ylist = M('fei')->where(['fid'=>$_POST['id']])->find();
								// dump($_POST['id']);
								// exit;
								if (empty($ylist['jname'])) {
									$data['jtype'] = $ulist[0]['m_type'];
									$data['jname'] = $ulist[0]['user'];
									$data['jtime'] = date('Y-m-d');
									$look['ju'] = '2';
													// dump($data);

									if (M('fei')->where(['fid'=>$_POST['id']])->save($data) > 0) {
										if (M('cost')->where(['id'=>$_POST['id']])->save($look) > 0) {
											echo '1111';
										}
									}
								}else{
									$data['gtype'] = $ulist[0]['m_type'];
									$data['gname'] = $ulist[0]['user'];
									$data['gtime'] = date('Y-m-d');
									$look['ju'] = '5';
													// dump($data);

									if (M('fei')->where(['fid'=>$_POST['id']])->save($data) > 0) {
										if (M('cost')->where(['id'=>$_POST['id']])->save($look) > 0) {
											echo '1111';
										}
									}
								}
								
								break;
							case '6':  //董事办
                $data['dtype'] = $ulist[0]['m_type'];
                    
                $data['dname'] = $ulist[0]['user'];
                $data['dtime'] = date('Y-m-d');
                
                $look['ju'] = '6';
                        // dump($data);
                        // exit;
                if (M('fei')->where(['fid'=>$_POST['id']])->save($data) > 0) {
                  if (M('cost')->where(['id'=>$_POST['id']])->save($look) > 0) {
                    echo '1111';
                  }
                }
                break;

								
						}
    }





    public function ftong()
    {
		$llist = $_POST;
		foreach ($llist as $k => $v) {
			// dump();
			// for ($i=0; $i <= $k ; $i++) { 
			// 	# code...
			// }
			$ment[]= $v;

			
		}
		$ments = $ment[0];
		// dump($ments);
		// exit;
		// $new= implode(',',$ments);
		// echo $new;
		// exit;
		// $arr = 'id='.$new;
		// // echo $arr;
		// // exit;
		// $llist = M('look')->where($arr)->select();
		// dump($ments);
		// exit;

		$ulist = M('member')->where(['uid'=>$_SESSION['uid']])->select();
		$alist = M('auth_group_access')->where(['uid'=>$_SESSION['uid']])->select();
		$glist = M('auth_group')->where(['id'=>$alist[0]['group_id']])->select();
		// $slist = M('look')->where(['id'=>['in',$ments]])->select();
		
		// dump($glist);
		// exit;
		// $data=[];
		// $ltt = M('look')->where(['id'=>['in',$ments]])->select();
		$data['stype'] = 1;
			switch ($ulist[0]['m_type']) {
					case '2':  //主管
						$data['ztype'] = $ulist[0]['m_type'];
						
						$data['zname'] = $ulist[0]['user'];
						$data['ztime'] = date('Y-m-d');
						$look['look'] = '1';
						// dump($data);
						// exit;

				        $c = [];
				        foreach ($ments as $k => $v) {
				            $c[$k]['fid'] = $v;
				            $c[$k]['ztype'] = $data['ztype'];
				            $c[$k]['zname'] = $data['zname'];
				            $c[$k]['ztime'] = $data['ztime'];
				            $c[$k]['stype'] = $data['stype'];
				            // $c[$k]['wtype'] = $data['wtype'];
				        }
				        // dump($c);
				        // exit;

						if (M('fei')->addAll($c) > 0) {
							if (M('cost')->where(['id'=>['in',$ments]])->save($look) > 0) {
								echo '1111';
							}
						}
						break;
					case '3':  //经理
						switch ($glist[0]['post']) {
							case '行政中心':
								
									$data['jtype'] = $ulist[0]['m_type'];
						
									$data['jname'] = $ulist[0]['user'];
									$data['jtime'] = date('Y-m-d');
									$look['look'] = '2';
									// dump($data);

									if (M('fei')->where(['fid'=>['in',$ments]])->save($data) > 0) {
										if (M('cost')->where(['id'=>['in',$ments]])->save($look) > 0) {
											echo '1111';
										}
									}
								
								break;

							case '采购中心':
								$data['jtype'] = $ulist[0]['m_type'];
						
								$data['jname'] = $ulist[0]['user'];
								$data['jtime'] = date('Y-m-d');
								$look['look'] = '2';
								// dump($data);

								if (M('fei')->where(['fid'=>['in',$ments]])->save($data) > 0) {
									if (M('cost')->where(['id'=>['in',$ments]])->save($look) > 0) {
										echo '1111';
									}
								}
								break;
							case '财务中心':
										$ylist = M('fei')->where(['fid'=>$ments[0]])->select();
										if (empty($ylist[0]['jname'])) {
											$data['jtype'] = $ulist[0]['m_type'];
								
											$data['jname'] = $ulist[0]['user'];
											$data['jtime'] = date('Y-m-d');
											$look['look'] = '2';
											// dump($data);

											if (M('fei')->where(['fid'=>['in',$ments]])->save($data) > 0) {
												if (M('cost')->where(['id'=>['in',$ments]])->save($look) > 0) {
													echo '1111';
												}
											}
										}else{
											$data['cjtype'] = $ulist[0]['m_type'];
											$data['cjname'] = $ulist[0]['user'];
											$data['cjtime'] = date('Y-m-d');
											$look['look'] = '4';
											// dump($data);

											if (M('fei')->where(['fid'=>['in',$ments]])->save($data) > 0) {
												if (M('cost')->where(['id'=>['in',$ments]])->save($look) > 0) {
													echo '1111';
												}
											}
										}
								break;
							
						}
					
						break;

					case '10':  //财务
						$data['ctype'] = $ulist[0]['m_type'];
						
						$data['cname'] = $ulist[0]['user'];
						$data['ctime'] = date('Y-m-d');
						$look['look'] = '3';
						// dump($data);

						if (M('fei')->where(['fid'=>['in',$ments]])->save($data) > 0) {
							if (M('cost')->where(['id'=>['in',$ments]])->save($look) > 0) {
								echo '1111';
							}
						}
						break;
					case '9':  //职能部门经理
					// echo '555';
					// exit;
						$cai = M('fei')->where(['fid'=>['in',$ments]])->select();
						// dump($cai);
						// exit;
							if (empty($cai[0]['cname'])) {
								$data['jtype'] = $ulist[0]['m_type'];
						
								$data['jname'] = $ulist[0]['user'];
								$data['jtime'] = date('Y-m-d');
								$look['look'] = '2';
								// dump($ments);
								// exit;

								if (M('fei')->where(['fid'=>['in',$ments]])->save($data) > 0) {
									if (M('cost')->where(['id'=>['in',$ments]])->save($look) > 0) {
										echo '1111';
									}
								}
							}else{
								$data['gtype'] = $ulist[0]['m_type'];
						
								$data['gname'] = $ulist[0]['user'];
								$data['gtime'] = date('Y-m-d');
								$look['look'] = '5';
								// dump($data);

								if (M('fei')->where(['fid'=>['in',$ments]])->save($data) > 0) {
									if (M('cost')->where(['id'=>['in',$ments]])->save($look) > 0) {
										echo '1111';
									}
								}
							}
						
						
						break;
					case '8':  //网络中心经理
						$data['jtype'] = $ulist[0]['m_type'];
						
						$data['jname'] = $ulist[0]['user'];
						$data['jtime'] = date('Y-m-d');
						$look['look'] = '2';
						// dump($data);

						if (M('fei')->where(['fid'=>['in',$ments]])->save($data) > 0) {
							if (M('cost')->where(['id'=>['in',$ments]])->save($look) > 0) {
								echo '1111';
							}
						}
						break;

					case '6':  //董事办
						$data['dtype'] = $ulist[0]['m_type'];
						
						$data['dname'] = $ulist[0]['user'];
						$data['dtime'] = date('Y-m-d');
						$look['look'] = '6';
						// dump($data);

						if (M('fei')->where(['fid'=>['in',$ments]])->save($data) > 0) {
							if (M('cost')->where(['id'=>['in',$ments]])->save($look) > 0) {
								echo '1111';
							}
						}
						break;
				}
    }



    public function fqju()
    {
      $llist = $_POST;
      // dump($llist);
      // exit;
      if (empty($llist['uids'])) {
        echo '3333';
        exit;
      }
      $arr[] = $llist['uids'];

      foreach ($arr as $k => $v) {
        // dump();
        // for ($i=0; $i <= $k ; $i++) { 
        //  # code...
        // }
        // dump($v);
        $ment[]= $v;
        // $ment['cent']= $v['cent'];


        
      }
      $data['content'] = $_POST['cent'];
      $ments = $ment[0];
      // dump($cent);
      // exit;
      $data['stype'] = '2';

      $ulist = M('member')->where(['uid'=>$_SESSION['uid']])->select();
      $alist = M('auth_group_access')->where(['uid'=>$_SESSION['uid']])->select();
      $glist = M('auth_group')->where(['id'=>$alist[0]['group_id']])->select();
      switch ($ulist[0]['m_type']) {
              case '3':  //经理
                switch ($glist[0]['post']) {
                 
                  case '财务中心':
                    $data['cjtype'] = $ulist[0]['m_type'];
                    
                    $data['cjname'] = $ulist[0]['user'];
                    $data['cjtime'] = date('Y-m-d');
                    $look['ju'] = '4';
                            // dump($data);

                    if (M('fei')->where(['fid'=>['in',$ments]])->save($data) > 0) {
                      if (M('cost')->where(['id'=>['in',$ments]])->save($look) > 0) {
                        echo '1111';
                      }
                    }
                    break;
                  
                  
                }
                break;
             
              case '10':  //财务
                $data['ctype'] = $ulist[0]['m_type'];
                    
                $data['cname'] = $ulist[0]['user'];
                $data['ctime'] = date('Y-m-d');
                $look['ju'] = '3';
                        // dump($data);

                if (M('fei')->where(['fid'=>['in',$ments]])->save($data) > 0) {
                  if (M('cost')->where(['id'=>['in',$ments]])->save($look) > 0) {
                    echo '1111';
                  }
                }
                break;
              case '9':  //职能总经理
                $data['gtype'] = $ulist[0]['m_type'];
                    
                $data['gname'] = $ulist[0]['user'];
                $data['gtime'] = date('Y-m-d');
                $look['ju'] = '5';
                        // dump($data);

                if (M('fei')->where(['fid'=>['in',$ments]])->save($data) > 0) {
                  if (M('cost')->where(['id'=>['in',$ments]])->save($look) > 0) {
                    echo '1111';
                  }
                }
                break;
              case '6':  //董事办
                $data['dtype'] = $ulist[0]['m_type'];
                    
                $data['dname'] = $ulist[0]['user'];
                $data['dtime'] = date('Y-m-d');
                $look['ju'] = '6';
                        // dump($data);

                if (M('fei')->where(['fid'=>['in',$ments]])->save($data) > 0) {
                  if (M('cost')->where(['id'=>['in',$ments]])->save($look) > 0) {
                    echo '1111';
                  }
                }
                break;

                
            }
    }




    public function jsuo()
    {
      $gid = M('auth_group_access')->where(['uid'=>$_SESSION['uid']])->select();
    // dump($gid);
    // exit;
    $glist = M('auth_group')->where(['id'=>$gid[0]['group_id']])->select();
    // dump($glist);
    // exit;
    $ulist = M('member')->where(['uid'=>$_SESSION['uid']])->select();
    $apost = $glist[0]['post'];
    // dump($_GET);
          switch ($ulist[0]['m_type']) {
            case '3':   //经理
                switch ($apost) {
                    case '财务中心':
                            $db = M("cost");
                        
                            $count = $db->where(['look'=>3,'ju'=>0])->count();
                            // dump($count);
                            // exit;
                            $pagecount = 20;
                            $page = new \Think\Page($count , $pagecount);
                            $page->parameter = $row; //此处的row是数组，为了传递查询条件
                            $page->setConfig('first');
                            $page->setConfig('prev','上一页');
                            $page->setConfig('next','下一页');
                            $page->setConfig('last','尾页');
                            $page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% 第 '.I('p',1).' 页/共 %TOTAL_PAGE% 页 ( '.$pagecount.' 条/页 共 %TOTAL_ROW% 条)');
                            $show = $page->show();
                            $list = $db->where(['look'=>3,'ju'=>0])->order('id desc')->limit($page->firstRow.','.$page->listRows)->select();
                            $title = '公司费用报销审批';


                            //---------------------------------------
                           
                            $lei = '财务';
                            $this->assign('list',$list);
                            $this->assign('lei',$lei);
                           
                            $this->assign('page',$show);
                            
                            $this->assign('title',$title);
                            $this->display();
                      break;
                    
                    
                  }





                  
                break;
              case '9':  //职能总经理
                  $db = M("cost");
                        
                  $count = $db->where(['look'=>4,'ju'=>0])->count();
                  // dump($count);
                  // exit;
                  $pagecount = 20;
                  $page = new \Think\Page($count , $pagecount);
                  $page->parameter = $row; //此处的row是数组，为了传递查询条件
                  $page->setConfig('first');
                  $page->setConfig('prev','上一页');
                  $page->setConfig('next','下一页');
                  $page->setConfig('last','尾页');
                  $page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% 第 '.I('p',1).' 页/共 %TOTAL_PAGE% 页 ( '.$pagecount.' 条/页 共 %TOTAL_ROW% 条)');
                  $show = $page->show();
                  $list = $db->where(['look'=>4,'ju'=>0])->order('id desc')->limit($page->firstRow.','.$page->listRows)->select();
                  $title = '公司费用报销审批';


                  //---------------------------------------
                           
                  $lei = '总经理';
                  $this->assign('list',$list);
                  $this->assign('lei',$lei);
                           
                  $this->assign('page',$show);
                            
                  $this->assign('title',$title);
                  $this->display();
                break;
          }
    }






    public function ping()
    {
     
      $plist = M('cost')->where(['id'=>$_GET['id']])->find();
      //  dump(I());
      // exit;
      // $filename = $plist['iname'];
     
      $url = './Public'.$plist['img'];
      // echo $url;
      // exit;
      // 
        header("Content-type: octet/stream");
        header("Content-disposition:attachment;filename=".$url.";");
        header("Content-Length:".filesize($url));
        readfile($url);
            // exit;
      // // dump(I());
      // $list = M('cost')->where(['id'=>$_POST['id']])->select();
      // // dump($list);
      // // exit;
      // if (!empty($list)) {
      //     $img = $list[0]['img'];
      //     $this->ajaxReturn($img);  
      // }else{
      //     $this->ajaxReturn(0,"没有图片！",0);
      // }

    }








    //查看所有通过
    public function fsuo()
    {
        $ulist = M('member')->where(['uid'=>$_SESSION['uid']])->select();
        $uname = $ulist[0]['user'];
        $alist = M('auth_group_access')->where(['uid'=>$_SESSION['uid']])->select();
        $glist = M('auth_group')->where(['id'=>$alist[0]['group_id']])->select();
        if ($ulist[0]['m_type'] >= 3) {
            $db = M("cost");
            // $where = "a_id=".$uid;
            $count = $db->where(['look'=>6,'ju'=>0,'que'=>0])->count();
            $pagecount = 9;
            $page = new \Think\Page($count , $pagecount);
                          // $row[] = '';
            $page->parameter = $row; //此处的row是数组，为了传递查询条件
            $page->setConfig('first','第一页');
            $page->setConfig('prev','上一页');
            $page->setConfig('next','下一页');
            $page->setConfig('last','尾页');
            $page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% 第 '.I('p',1).' 页/共 %TOTAL_PAGE% 页 ( '.$pagecount.' 条/页 共 %TOTAL_ROW% 条)');
            $show = $page->show();
            $list = $db->where(['look'=>6,'ju'=>0,'que'=>0])->order('id desc')->limit($page->firstRow.','.$page->listRows)->select();
            $title = '已通过报销审批';
            $lei = '1';
            $this->assign('list',$list);
            $this->assign('lei',$lei);
            // $this->assign('coun',$coun);
            // $this->assign('dao',$dao);
            // $this->assign('lei',$lei);
            $this->assign('page',$show);
            $this->assign('title',$title);
            $this->display();
        }else{
            $db = M("cost");
            // $where = "a_id=".$uid;
            $count = $db->where(['look'=>6,'ju'=>0,'uname'=>$uname])->count();
            $pagecount = 9;
            $page = new \Think\Page($count , $pagecount);
                          // $row[] = '';
            $page->parameter = $row; //此处的row是数组，为了传递查询条件
            $page->setConfig('first','第一页');
            $page->setConfig('prev','上一页');
            $page->setConfig('next','下一页');
            $page->setConfig('last','尾页');
            $page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% 第 '.I('p',1).' 页/共 %TOTAL_PAGE% 页 ( '.$pagecount.' 条/页 共 %TOTAL_ROW% 条)');
            $show = $page->show();
            $list = $db->where(['look'=>6,'ju'=>0,'uname'=>$uname])->order('id desc')->limit($page->firstRow.','.$page->listRows)->select();
            $title = '已通过报销审批';
            $this->assign('list',$list);
            // $this->assign('coun',$coun);
            // $this->assign('dao',$dao);
            // $this->assign('lei',$lei);
            $this->assign('page',$show);
            $this->assign('title',$title);
            $this->display();
        }
       

    }






    //查看所有拒绝
    public function fjue()
    {
        $ulist = M('member')->where(['uid'=>$_SESSION['uid']])->select();
        $uname = $ulist[0]['user'];
        $alist = M('auth_group_access')->where(['uid'=>$_SESSION['uid']])->select();
        $glist = M('auth_group')->where(['id'=>$alist[0]['group_id']])->select();
        if ($ulist[0]['m_type'] >= 3) {
            switch ($ulist[0]['m_type']) {
                case '3':   //经理
                  $db = M("cost");
                  // $apost = $glist[0]['post'];
                  // $x_list = M('look')->where(['look'=>0,'ment'=>$apost,'ju'=>0,'type'=>0])->order('id DESC')->select();
                  $count = $db->join('oa_fei as t1 on t1.fid = oa_cost.id')->where(['oa_cost.ju'=>['in',[3,4,5,6]]])->count();
                  // dump($count);
                  // exit;
                  $pagecount = 10;
                  $page = new \Think\Page($count , $pagecount);
                  // $row[] = '';
                  $page->parameter = $row; //此处的row是数组，为了传递查询条件
                  $page->setConfig('first');
                  $page->setConfig('prev','上一页');
                  $page->setConfig('next','下一页');
                  $page->setConfig('last','尾页');
                  $page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% 第 '.I('p',1).' 页/共 %TOTAL_PAGE% 页 ( '.$pagecount.' 条/页 共 %TOTAL_ROW% 条)');
                  $show = $page->show();
                  $list = $db->join('oa_fei as t1 on t1.fid = oa_cost.id')->where(['oa_cost.ju'=>['in',[3,4,5,6]]])->order('ment desc')->limit($page->firstRow.','.$page->listRows)->select();
                  // $xnum = M('look')->where(['look'=>0,'ment'=>$apost,'ju'=>0,'type'=>0])->count();
                  // $gnum = M('look')->where(['look'=>0,'ment'=>$apost,'ju'=>0,'type'=>2])->count();
                  // $jnum = M('look')->where(['look'=>0,'ment'=>$apost,'ju'=>0,'type'=>1])->count();
                  // $y_list = M('cost')->where(['look'=>0,'ment'=>$apost,'ju'=>0,])->order('id DESC')->limit(5)->select();
                   $title = '已被拒绝报销审批';
                  $this->assign('list',$list);
                  $this->assign('title',$title);
                  $this->assign('page',$show);
                  // $this->assign('xnum',$xnum);
                  // $this->assign('gnum',$gnum);
                  // $this->assign('jnum',$jnum);
                  // $this->assign('y_list',$y_list);
                  $this->display();
                  break;
                case '10':   //财务
                  $db = M("cost");
                  // $apost = $glist[0]['post'];
                  // $x_list = M('look')->where(['look'=>0,'ment'=>$apost,'ju'=>0,'type'=>0])->order('id DESC')->select();
                  $count = $db->join('oa_fei as t1 on t1.fid = oa_cost.id')->where(['oa_cost.ju'=>['in',[4,5,6]]])->count();
                  // dump($count);
                  // exit;
                  $pagecount = 10;
                  $page = new \Think\Page($count , $pagecount);
                  // $row[] = '';
                  $page->parameter = $row; //此处的row是数组，为了传递查询条件
                  $page->setConfig('first');
                  $page->setConfig('prev','上一页');
                  $page->setConfig('next','下一页');
                  $page->setConfig('last','尾页');
                  $page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% 第 '.I('p',1).' 页/共 %TOTAL_PAGE% 页 ( '.$pagecount.' 条/页 共 %TOTAL_ROW% 条)');
                  $show = $page->show();
                  $list = $db->join('oa_fei as t1 on t1.fid = oa_cost.id')->where(['oa_cost.ju'=>['in',[3,4,5,6]]])->order('ment desc')->limit($page->firstRow.','.$page->listRows)->select();
                  // $xnum = M('look')->where(['look'=>0,'ment'=>$apost,'ju'=>0,'type'=>0])->count();
                  // $gnum = M('look')->where(['look'=>0,'ment'=>$apost,'ju'=>0,'type'=>2])->count();
                  // $jnum = M('look')->where(['look'=>0,'ment'=>$apost,'ju'=>0,'type'=>1])->count();
                  // $y_list = M('cost')->where(['look'=>0,'ment'=>$apost,'ju'=>0,])->order('id DESC')->limit(5)->select();
                  $this->assign('list',$list);
                  $this->assign('page',$show);
                   $title = '已被拒绝报销审批';
                  $this->assign('title',$title);
                  // $this->assign('xnum',$xnum);
                  // $this->assign('gnum',$gnum);
                  // $this->assign('jnum',$jnum);
                  // $this->assign('y_list',$y_list);
                  $this->display();
                  break;





                case '6':   //财务
                  $db = M("cost");
                  // $apost = $glist[0]['post'];
                  // $x_list = M('look')->where(['look'=>0,'ment'=>$apost,'ju'=>0,'type'=>0])->order('id DESC')->select();
                  $count = $db->join('oa_fei as t1 on t1.fid = oa_cost.id')->where(['oa_cost.ju'=>'6'])->count();
                  // dump($count);
                  // exit;
                  $pagecount = 10;
                  $page = new \Think\Page($count , $pagecount);
                  // $row[] = '';
                  $page->parameter = $row; //此处的row是数组，为了传递查询条件
                  $page->setConfig('first');
                  $page->setConfig('prev','上一页');
                  $page->setConfig('next','下一页');
                  $page->setConfig('last','尾页');
                  $page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% 第 '.I('p',1).' 页/共 %TOTAL_PAGE% 页 ( '.$pagecount.' 条/页 共 %TOTAL_ROW% 条)');
                  $show = $page->show();
                  $list = $db->join('oa_fei as t1 on t1.fid = oa_cost.id')->where(['oa_cost.ju'=>'6'])->order('ment desc')->limit($page->firstRow.','.$page->listRows)->select();
                 
                  $this->assign('list',$list);
                  $this->assign('page',$show);
                    $title = '已被拒绝报销审批';
                  $this->assign('title',$title);
               
                  $this->display();
                  break;
                case '9':   //总经理
                  $db = M("cost");
                  // $apost = $glist[0]['post'];
                  // $x_list = M('look')->where(['look'=>0,'ment'=>$apost,'ju'=>0,'type'=>0])->order('id DESC')->select();
                  $count = $db->join('oa_fei as t1 on t1.fid = oa_cost.id')->where(['oa_cost.ju'=>['in',[3,4,5,6]]])->count();
                  // dump($count);
                  // exit;
                  $pagecount = 10;
                  $page = new \Think\Page($count , $pagecount);
                  // $row[] = '';
                  $page->parameter = $row; //此处的row是数组，为了传递查询条件
                  $page->setConfig('first');
                  $page->setConfig('prev','上一页');
                  $page->setConfig('next','下一页');
                  $page->setConfig('last','尾页');
                  $page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% 第 '.I('p',1).' 页/共 %TOTAL_PAGE% 页 ( '.$pagecount.' 条/页 共 %TOTAL_ROW% 条)');
                  $show = $page->show();
                  $list = $db->join('oa_fei as t1 on t1.fid = oa_cost.id')->where(['oa_cost.ju'=>['in',[3,4,5,6]]])->order('ment desc')->limit($page->firstRow.','.$page->listRows)->select();
                   $title = '已被拒绝报销审批';
                  $this->assign('title',$title);
                  $this->assign('list',$list);
                  $this->assign('page',$show);
                  
                  $this->display();
                  break;
                case '8':   //总经理
                  $db = M("cost");
                  // $apost = $glist[0]['post'];
                  // $x_list = M('look')->where(['look'=>0,'ment'=>$apost,'ju'=>0,'type'=>0])->order('id DESC')->select();
                  $count = $db->join('oa_fei as t1 on t1.fid = oa_cost.id')->where(['oa_cost.ju'=>['in',[3,4,5,6]]])->count();
                  // dump($count);
                  // exit;
                  $pagecount = 10;
                  $page = new \Think\Page($count , $pagecount);
                  // $row[] = '';
                  $page->parameter = $row; //此处的row是数组，为了传递查询条件
                  $page->setConfig('first');
                  $page->setConfig('prev','上一页');
                  $page->setConfig('next','下一页');
                  $page->setConfig('last','尾页');
                  $page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% 第 '.I('p',1).' 页/共 %TOTAL_PAGE% 页 ( '.$pagecount.' 条/页 共 %TOTAL_ROW% 条)');
                  $show = $page->show();
                  $list = $db->join('oa_fei as t1 on t1.fid = oa_cost.id')->where(['oa_cost.ju'=>['in',[3,4,5,6]]])->order('ment desc')->limit($page->firstRow.','.$page->listRows)->select();
                   $title = '已被拒绝报销审批';
                  $this->assign('title',$title);
                  $this->assign('list',$list);
                  $this->assign('page',$show);
                  
                  $this->display();
                  break;
            }
        }else{
            $db = M("cost");
            
            $count = $db->join('oa_fei as t1 on t1.fid = oa_cost.id')->where(['oa_cost.ju'=>['neq',0],'oa_cost.uname'=>$uname])->count();
            // dump($count);
            // exit;
            $pagecount = 15;
            $page = new \Think\Page($count , $pagecount);

                          // $row[] = '';
            $page->parameter = $row; //此处的row是数组，为了传递查询条件
            $page->setConfig('first','第一页');
            $page->setConfig('prev','上一页');
            $page->setConfig('next','下一页');
            $page->setConfig('last','尾页');
            $page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% 第 '.I('p',1).' 页/共 %TOTAL_PAGE% 页 ( '.$pagecount.' 条/页 共 %TOTAL_ROW% 条)');
            $show = $page->show();

            $list = $db->join('oa_fei as t1 on t1.fid = oa_cost.id')->where(['oa_cost.ju'=>['neq',0],'oa_cost.uname'=>$uname])->order('time desc')->limit($page->firstRow.','.$page->listRows)->select();

            // dump($list);
            // exit;
            $title = '已被拒绝报销审批';
            $this->assign('title',$title);
            $this->assign('list',$list);
            // $this->assign('coun',$coun);
            // $this->assign('dao',$dao);
            // $this->assign('lei',$lei);
            $this->assign('page',$show);
            $this->assign('title',$title);
            $this->display();
        }
       

    }





    public function xiang()
    {
      
      $list = M('cost')->join('oa_fei as t1 on t1.fid = oa_cost.id')->where(['oa_cost.id'=>$_GET['id']])->select();
      // dump($list);
      // exit;
      $this->assign('list',$list);
      $this->display();
    }


    public function que()
    { 
      // dump(I());
      $llist = M('cost')->where(['id'=>$_POST['id']])->find();
      // dump($llist);
      // exit;
      $que['que'] = '1';
      // $que['number'] = $llist['number'] - $llist['num'];
      // $number['number'] = $llist['number'] - $llist['num'];
      // dump($que);
      // exit;
      if (M('cost')->where(['id'=>$_POST['id']])->save($que) > 0 ) {
        echo '1111'; 
      }else{
        echo '2222';
      }


    }



}